﻿<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>角色管理</title>
	<jsp:include page="/resources/inc/head.jsp" />
</head>
<body>
<div id="main">
	<div id="toolbar">
		<shiro:hasPermission name="upms:role:create">
			<a class="waves-effect waves-button" href="javascript:;"
			   onclick="Common.openPage({url:'${basePath}/manage/role/create',title:'新增角色'})">
				<i class="zmdi zmdi-plus"></i> 新增角色</a>
		</shiro:hasPermission>
		<shiro:hasPermission name="upms:role:update">
			<a class="waves-effect waves-button" href="javascript:;"
			   onclick="Common.toolBarUpdate({url:'${basePath}/manage/role/update/',id:'roleId',title:'编辑角色'})">
				<i class="zmdi zmdi-edit"></i> 编辑角色</a>
		</shiro:hasPermission>
		<shiro:hasPermission name="upms:role:delete">
			<a class="waves-effect waves-button" href="javascript:;"
			   onclick="Common.batchDelete({url:'${basePath}/manage/role/delete/',id:'roleId'})">
				<i class="zmdi zmdi-close"></i> 删除角色</a>
		</shiro:hasPermission>
		<shiro:hasPermission name="upms:role:permission">
			<a class="waves-effect waves-button" href="javascript:;"
			   onclick="permissionAction()">
				<i class="zmdi zmdi-key"></i> 角色权限</a>
		</shiro:hasPermission>
	</div>
	<table id="table"></table>
</div>
<jsp:include page="/resources/inc/footer.jsp" />
<script>
var $table = $('#table');
$(function() {
	// bootstrap table初始化
	$table.bootstrapTable({
		url: '${basePath}/manage/role/list',
		height: getHeight(),
		striped: true,
		search: true,
		showRefresh: true,
		showColumns: true,
		minimumCountColumns: 2,
		clickToSelect: true,
		detailView: true,
		detailFormatter: 'detailFormatter',
		pagination: true,
		paginationLoop: false,
		queryParamsType: "",
		sidePagination: 'server',
		silentSort: false,
		smartDisplay: false,
		escape: true,
		searchOnEnterKey: true,
		idField: 'roleId',
		maintainSelected: true,
		toolbar: '#toolbar',
		columns: [
			{field: 'ck', checkbox: true},
			{field: 'roleId', title: '编号', sortable: true, align: 'center'},
			{field: 'name', title: '角色名称'},
			{field: 'title', title: '角色标题'},
            {field: 'description', title: '角色描述'},
			{field: 'action', title: '操作', align: 'center', formatter: 'actionFormatter', events: 'actionEvents', clickToSelect: false}
		]
	});
});


var updateData = {
	title: "编辑角色"
};
var deleteData = {
	url: "${basePath}/manage/role/delete/"
};
// 格式化操作按钮
function actionFormatter(value, row, index) {
	var html = "";
	updateData.url = "${basePath}/manage/role/update/" + row.roleId;
	deleteData.id = row.roleId;
	<shiro:hasPermission name="oa:hr:position:update">
	html += getPageHtml(updateData) + "  ";
	</shiro:hasPermission>
	<shiro:hasPermission name="oa:hr:position:delete">
	html += getDeleteHtml(deleteData) + "  ";
	</shiro:hasPermission>
	return html;
}


// 角色权限
function permissionAction() {
	var rows = $table.bootstrapTable('getSelections');
	if (rows.length != 1) {
		layer.msg('请选择一条记录');
	} else {
		var roleId = rows[0].roleId;
		Common.openPage({url:'${basePath}/manage/role/permission/'+roleId,title:'角色权限'});
	}
}

</script>
</body>
</html>